package com.abc.core.instance.bo;

import com.abc.core.util.CellSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 实例值
 */
@JsonSerialize(using = CellSerializer.class)
@Data
public class Cell implements Cloneable {

    private Long id;
    private Long rootId;
    /**
     * 上层父Cell的id
     */
    private Long parentId;
    private String dnaCode;
    /**
     * 操作标记:增,改,删,读
     */
    private String operationFlag;
    /**
     * Cell所在的Inst对象
     */
    private Inst owner;
    /**
     * 实例信息中每一个属性的值
     * key为Vd对象 vdName,即属性名
     * 快速定位 Va对象
     */
    private Map<String, Va> vas = new HashMap<>();
    /**
     * 每一个孩子Dna对象的实例对象
     */
    private Map<String, Inst> children = new HashMap<>();

    public void setVaByName(String name, String value) {
        Va va = new Va();
        va.setCode(name);
        va.setName(name);
        va.setDataType("string");
        va.setValue(value);
        vas.put(name, va);
    }

    public void addChildInst(Inst accountInst) {
        children.put(accountInst.getDnaName(), accountInst);
    }


    public void addChildInst(String dnaName, String dnaCode2, Inst accountInst) {
        children.put(dnaName, accountInst);
    }

    public Inst getChildInst(String childName) {
        return children.get(childName);
    }

    public String getRawStringByName(String name) {
        Va va = vas.get(name);
        if (va != null) {
            return va.getRawString();
        }
        return null;
    }

    public Boolean getRawBoolByName(String name) {
        Va va = vas.get(name);
        if (va == null) {
            return null;
        }
        return va.getRawBoolean();
    }

    public Va getVaByName(String vdName) {
        return vas.get(vdName);
    }

    public Object getValue(String name) {
        return null;
    }


}
